﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Utils
{
    public static class Enum<T>
    {
        public static string GetName(T value)
        {
            return Enum.GetName(typeof(T), value);
        }

        public static T Parse(string value)
        {
#if SILVERLIGHT
		        return (T)Enum.Parse(typeof(T), value, false);
#else
            return (T)Enum.Parse(typeof(T), value);
#endif
        }

        public static IList<T> GetValues()
        {
            IList<T> list = new List<T>();
            foreach (object value in Enum.GetValues(typeof(T)))
            {
                list.Add((T)value);
            }
            return list;
        }

        public static IList<string> GetNames()
        {
            return Enum.GetNames(typeof(T));
        }
    }

    public static class EnumUtil
    {
        public static T SetFlag<T>(T _enum, T flag)
        {
            var enumInt = (int)(object) _enum;
            var flagInt = (int)(object)flag;

            enumInt |= flagInt;

            return (T)(object) enumInt;
        }

        public static T RemoveFlag<T>(T _enum, T flag)
        {
            var enumInt = (int)(object)_enum;
            var flagInt = (int)(object)flag;

            enumInt &= ~flagInt;

            return (T)(object)enumInt;
        }
    }
}
